package cate.game.play.skill.passive.hero;

import cate.common.util.XT;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.skill.FighterCD;
import cate.game.play.skill.passive.PassiveHandler;

import java.util.List;

/**
 * 生命值低于60%时净化自身，附加【魔化】 每场战斗只能触发1次
 */
public class 拈花焚魄PH extends PassiveHandler {

	private int 血量;

	private List<Integer> buffList;

	private String 魔化标签;

	private int 冷却回合;

	//血量=6000&buff=??#??&魔化标签=魔化&冷却回合=0
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		血量 = args.getInt("血量", 0);
		buffList = args.getIntList("buff");
		魔化标签 = args.get("魔化标签");
		冷却回合 = args.getInt("冷却回合", 0);
	}

	@Override
	public void parseExt(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		buffList = XT.merge(buffList, args.getIntList("buff"));
		冷却回合 = args.getInt("冷却回合", 冷却回合);
	}

	private int lastSettleRound;

	@Override
	public void onMoveDone(MoveCtx move, TimeActionCtx action) {
		if (lastSettleRound > 0) {
			if (冷却回合 <= 0) {
				return;
			} else {
				if (FighterCD.inCD(lastSettleRound, 冷却回合, move.getRound().index)) {
					return;
				}
			}
		}
		if (skill.owner.buff.containTags(魔化标签)) {
			return;
		}
		if (skill.owner.isDead()) {
			return;
		}
		if (skill.owner.attr.total().hpCurRate() > 血量) {
			return;
		}
		skill.owner.buff.tryDispelBad(action);
		if (XT.isNotBlank(buffList)) {
			for (Integer id : buffList) {
				skill.owner.buff.tryAddByTid(action, id);
			}
		}
		lastSettleRound = action.getRound().index;
	}
}
